<template lang="html">
  <div class="home">

    <!-- <div class='clearfix'>
      <el-button type="danger" class='pull-right mb10' icon="el-icon-delete" style='margin-right:10px;' @click="tourl('/content/trash')">回收箱</el-button>
    </div> -->

    <div class='searchView'>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="标题">
          <el-input v-model='searchForm.title'></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click='getList(1)'>查询</el-button>
        </el-form-item>
<!--         <el-form-item class='pull-right'>
          <el-button type="primary" @click='dialogVisible = true,reset()'>创建活动</el-button>
        </el-form-item> -->
      </el-form>
    </div>

    <div class='tableView'>
      <el-tag type="info" class='mb10'>共{{totalData}}条记录</el-tag>
      <el-table
        ref="multipleTable"
        :data="tableData"
        v-loading='loading'
        align='center'
        border
        height='500'
        tooltip-effect="dark">

        <el-table-column
        align='center'
        label="文章标题">
          <template slot-scope="scope">
            <a 
              :href="'http://www.utter.cn/#/whiterow/articleinfo?type=white&identify='+scope.row.identify + '&id='+scope.row.id" 
              target='_blank'>
                {{scope.row.title}}
            </a>
          </template>
        </el-table-column>

        <el-table-column
        align='center'
        label="查看">
          <template slot-scope="scope">
            <a 
              :href="'http://www.utter.cn/#/whiterow/articleinfo?type=white&identify='+scope.row.identify + '&id='+scope.row.id" 
              target='_blank'>
                跳转查看
            </a>
          </template>
        </el-table-column>

        <el-table-column
        align='center'
        prop='createTime'
        label="创建时间">
        </el-table-column>

        <el-table-column
        align='center'
        prop='viewCount'
        label="查看数">
        </el-table-column>

        <el-table-column
        align='center'
        prop='commentCount'
        label="评论数">
        </el-table-column>

        <el-table-column
        align='center'
        prop='favorityCount'
        label="收藏数">
        </el-table-column>

        <el-table-column
        align='center'
        prop='likeCount'
        label="点赞数">
        </el-table-column>

        <el-table-column
        label=""
        width='220'
        align='center'>
          <template slot-scope="scope">
            <el-button size='mini' type="danger" @click='delIt(scope.row.id)'>删除</el-button>
          </template>
        </el-table-column>

      </el-table>

      <div class="pageBlock">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next, jumper, sizes"
          :total="totalData">
        </el-pagination>
      </div>
    </div>

  </div>
</template>
<script>
export default {

  data () {
    return {
      tableData:[],
      loading:false,
      totalData:0,
      pageSize:10,
      currentPage:1,
      dialogVisible:false,
      searchForm:{
        title:''
      }
    }
  },
  watch:{

  },
  methods:{
    delIt(id){
      this.$confirm('是否确认删除该文章？',{center:true})
      .then(res =>{
        this.loading = true;
        tools.ajax({
            url:`/v1/article/deleteArticleInfo?articleId=${id}`,
            type:'DELETE',
            data:{
              articleId:id
            }
        })
        .then(res => {
          this.loading = false;
          if(res.code == 200){
            tools.toastOk('删除成功');
            this.getList(1);
          }
        })
        .catch(e => {
          this.loading = false;
        })

      }).catch( e=> {})
    },
    tourl(url,query){
      tools.router.push({path:url,query:query || {}})
    },
    getList(page){
      if(page){
        this.currentPage = page;
      }

      let param = {
        page:this.currentPage,
        pageSize:this.pageSize
      };

      for(let i in this.searchForm){
        if(this.searchForm[i]){
          param[i] = this.searchForm[i];
        }
      }

      this.loading = true;
      tools.ajax({
        url:'/v1/article/getArticleList',
        data:param,
        type:'POST'
      })
      .then(res => {
        this.loading = false;
        if(res.code == 200){
          this.tableData = res.data.rows;
          this.totalData = +res.data.total;
        }
      })
      .catch(e => {
        this.loading = false;
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getList();
    }
  },
  mounted(){
    var _this = this;
    this.getList();
  },
  components:{
  }
}
</script>

<style scoped lang='scss'>
  @import '../../assets/scss/tool.scss';
  .poster{

  }

  .cover{
    max-width: 200px;
    max-height: 100px;
  }
</style>